﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
using Quartz;
using Quartz.Impl;
using System.Reflection;
using Quartz.Impl.Triggers;
using FTchina.Library;
using FTchina.Logic;
using System.Globalization;

public partial class ui_Quartz_CronMaker : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DDLInit();
        }

    }


    /// <summary>
    /// 初始化绑定各控件
    /// </summary>
    protected void DDLInit()
    {
        ControlBindHelper.DropDownListMinutes(ddlGenMinuteStart);
        ControlBindHelper.DropDownListMinutes(ddlGenMinuteEnd);
        ControlBindHelper.DropDownListHours(ddlGenHourStart);
        ControlBindHelper.DropDownListHours(ddlGenHourEnd);
        ControlBindHelper.DropDownListDay(ddlGenDayStart);
        ControlBindHelper.DropDownListDay(ddlGenDayEnd);
        ControlBindHelper.DropDownListMonth(ddlGenMonthStart);
        ControlBindHelper.DropDownListMonth(ddlGenMonthEnd);
        ControlBindHelper.DropDownListWeek(ddlGenWeekStart);
        ControlBindHelper.DropDownListWeek(ddlGenWeekEnd);

    }



    protected void Exp_Changed(object sender, EventArgs e)
    {
        //处理分
        if (ddlGenMinuteStart.SelectedValue == ddlGenMinuteEnd.SelectedValue)
        {
            txbExpMinutes.Text = ddlGenMinuteStart.SelectedValue + "/" + txbGenMinute.Text;
        }
        else
        {
            txbExpMinutes.Text = ddlGenMinuteStart.SelectedValue + "-" + ddlGenMinuteEnd.SelectedValue + "/" + txbGenMinute.Text;
        }

        //处理小时
        if (ddlGenHourStart.SelectedValue == ddlGenHourEnd.SelectedValue)
        {
            txbExpHours.Text = ddlGenHourStart.SelectedValue + "/" + txbGenHour.Text;

        }
        else
        {
            txbExpHours.Text = ddlGenHourStart.SelectedValue + "-" + ddlGenHourEnd.SelectedValue + "/" + txbGenHour.Text;
        }


        //处理天
        if (ddlGenDayStart.SelectedValue == ddlGenDayEnd.SelectedValue)
        {
            txbExpDays.Text = ddlGenDayStart.SelectedValue + "/" + txbGenDay.Text;

        }
        else
        {
            txbExpDays.Text = ddlGenDayStart.SelectedValue + "-" + ddlGenDayEnd.SelectedValue + "/" + txbGenDay.Text;
        }


        //处理月份
        if (ddlGenMonthStart.SelectedValue == ddlGenMonthEnd.SelectedValue)
        {
            txbExpMonths.Text = ddlGenMonthStart.SelectedValue + "/" + txbGenMonth.Text;
        }
        else
        {
            txbExpMonths.Text = ddlGenMonthStart.SelectedValue + "-" + ddlGenMonthEnd.SelectedValue + "/" + txbGenMonth.Text;
        }
        if (ddlGenWeekStart.SelectedValue == ddlGenWeekEnd.SelectedValue)
        {
            txbExpDayOfWeek.Text = "?";
        }
        else
        {
            txbExpDayOfWeek.Text = ddlGenWeekStart.SelectedValue + "-" + ddlGenWeekEnd.SelectedValue;
        }
    }

    protected void btnMakeExp_Click(object sender, EventArgs e)
    {
        txbexp.Text = txbExpSeconds.Text + " "
            + txbExpMinutes.Text + " "
            + txbExpHours.Text + " "
            + txbExpDays.Text + " "
            + txbExpMonths.Text + " "
            + txbExpDayOfWeek.Text;
    }


    /// <summary>
    /// 数据库里的字符串转化为时间
    /// </summary>
    /// <param name="columnValue"></param>
    /// <returns></returns>
    public DateTime? GetDateTimeFromDbValue(object columnValue)
    {
        if (columnValue != null && columnValue != DBNull.Value)
        {
            var ticks = Convert.ToInt64(columnValue, CultureInfo.CurrentCulture);
            if (ticks > 0)
            {
                return new DateTimeOffset(ticks, TimeSpan.Zero).DateTime.ToLocalTime();
            }
        }
        return null;
    }
}